#ifndef Algebra_Error_h
#define Algebra_Error_h

#include "AlgebraModule.h"
#include <stdexcept>

SG_NAMESPACE_OPEN

namespace Algebra
{
    /** Enum for reporting the status of a computation. */
    enum ComputationInfo
    {
        /** Computation was successful. */
        Success = 0,
        /** The provided data did not satisfy the prerequisites. */
        NumericalIssue = 1,
        /** Iterative procedure did not converge. */
        NoConvergence = 2,
        /** The inputs are invalid, or the algorithm has been improperly called.
         * When assertions are enabled, such errors trigger an assert. */
        InvalidInput = 3
    };

    // Alias to avoid the tiresome long names
    typedef ComputationInfo Info_t;

    /** Errors detected during runtime. */
    class RuntimeException : public std::exception
    {
      public:
        std::string msg;

        RuntimeException (const char* _func, const char* _file, int _line, const char* format, ...);
        const char* what () const noexcept override;
    };

    /**
     * Helper to throw exceptions.
     */
    //@{
#define SG_FATAL(...)                                                       \
    {                                                                       \
        throw RuntimeException (__func__, __FILE__, __LINE__, __VA_ARGS__); \
    }
#define SG_ERROR(...)                                                       \
    {                                                                       \
        throw RuntimeException (__func__, __FILE__, __LINE__, __VA_ARGS__); \
    }
}  // namespace Algebra

SG_NAMESPACE_CLOSE

#endif  // Base_Error_h